package com.song.study.spring.Config;

import com.song.study.spring.Entity.Car;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @Author ZhangGuisong
 * @Date 2021/4/24-20:37
 */
@Configuration
@ComponentScan("com.song.study.spring.Entity")
public class BeanCycle {
    /**
     *  自定义bean 对象的创建和销毁
     *
     *  bean 对象在容器加载的完，对象就创建好啦，在容器关闭后，bean对象被销毁，
     *
     *  prototype:在多实例的情况下，bean对象是在获取的时候，才创建,容器关闭后，对象没有被销毁
     *
     *
     *  实现InitializingBean
     *  DisposableBean
     *
     *  BeanPostProcessor的原理
     *   populateBean(beanName, mbd, instanceWrapper);
     *   initializeBean{
     *        applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);
     *        invokeInitMethods(beanName, wrappedBean, mbd);
     *       wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
     *   }
     *
     *
     *
     *
     */
   // @Scope(value = "prototype")
    @Bean(value="car",initMethod="init",destroyMethod="destroy")
    public Car getCar(){
        System.out.println(" car object creata ok");
        return new Car();
    }
}
